/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:itsm-gateway
 * Create Time: 2016年1月30日 下午3:38:46
 */
package com.lenovo.lmrp.server.eventrecorder.repository;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.lenovo.lmrp.server.eventrecorder.domain.ticket.IEventRepository;

/**
 * 
 * @author wujin
 * @version v1.0
 */
public abstract class ARepositoryFactory {
    private static ARepositoryFactory factory;
    
    public static ARepositoryFactory getFactory() {
        return factory;
    }
    
    @Inject
    public static void setFactory(ARepositoryFactory factory) {
        ARepositoryFactory.factory = factory;
    }
    
    public abstract IEventRepository getEventRepostory();
    
    @Named("default")
    public static class RepositoryFactoryImpl extends ARepositoryFactory {
        @Inject
        private IEventRepository eventRepository;

        @Override
        public IEventRepository getEventRepostory() {
            return eventRepository;
        }  
    }
    
    public static class RepositoryModule implements Module {

        @Override
        public void configure(Binder binder) {
            binder.bind(CassandraDataSource.class).in(Scopes.SINGLETON);
            
            binder.bind(IEventRepository.class).to(EventRepository.class).in(Scopes.SINGLETON);
            
            binder.bind(ARepositoryFactory.class).to(RepositoryFactoryImpl.class).in(Scopes.SINGLETON);
            
            binder.requestStaticInjection(ARepositoryFactory.class);
            

        }
        
    }
}
